﻿//可使用權限    無
//2010-05-20    判斷網頁錯誤原因

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using DataAccess;

namespace iEN.Announce
{
    public partial class ErrorPage : System.Web.UI.Page
    {
        #region protected void Page_Load(object sender, EventArgs e)        //頁面初始，擷取網頁錯誤訊息
        protected void Page_Load(object sender, EventArgs e)
        {
            if (CommonFun.Utilities.LastError.InnerException == null)
            {
                return;
            }

            // 取得錯誤訊息
            string strErrMsg = "錯誤訊息：" + CommonFun.Utilities.LastError.InnerException.Message;

            // 取得錯誤的NameSpace
            string strErrNameSpace = "錯誤範圍：" + CommonFun.Utilities.LastError.InnerException.Source;

            // 取得錯誤的詳細資料
            string strErrDetail = "錯誤資料：" + CommonFun.Utilities.LastError.InnerException.StackTrace;

            // 取得錯誤的頁面URL
            string strErrURL = "錯誤頁面：" + Request["aspxerrorpath"].ToString();


            //避免資料庫連線異常
            if (!new CommonFun().AddErrorMsg(strErrURL, strErrMsg, "NameSpace：" + strErrNameSpace + "，Detail：" + strErrDetail))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", "alert('資料庫連線異常！')", true);
                return;
            }
            else
            {
                //顯示錯誤訊息
                lblErrorUrl.Text = strErrURL;
                lblErrorMsg.Text = strErrMsg;
                lblErrNameSpace.Text = strErrNameSpace;
                lblErrDetail.Text = strErrDetail;
            }
        }
        #endregion

        #region protected void btnLogout_Click(object sender, EventArgs e)      //按下『登出』按鈕
        protected void btnLogout_Click(object sender, EventArgs e)
        {
            Session["SysAdmin"] = "";
            Session["LoginID"] = "";
            Session["LoginName"] = "";
            Session["LoginIP"] = "";
            Response.Redirect("../Login.aspx");
        }
        #endregion
    }
}
